<?php

class Pictet2_Views_Html extends Pictet2_Views_Abstract {
	
	public function render($page) {
		if(!file_exists(ROOT_DIR . DS . ".css" . DS . "pictet.css")) {
			if(!file_exists(ROOT_DIR . DS . ".css")) {
				mkdir(ROOT_DIR . DS . ".css");
			}
			file_put_contents(ROOT_DIR . DS . ".css" . DS . "pictet.css", $this->_css());
		}
		
		print $this->_cleanTemplates($this->_header());
		switch($page) {
			case "gallery":
				$this->_default();
				break;
			case "display":
				$this->_view();
				break;
		}
		print $this->_cleanTemplates($this->_footer());
	}
	
	private function _default() {
		
		
		print "<div id=\"holder\">";
		$this->_subDirs();
		$this->_galleryNav();
		if($this->_vars["files"]) {
			print "<ul id=\"gallery\">\n";
			foreach($this->_vars["files"] as $file) {
				print "<li>\n";
				print "<div><a href=\"" . URL_CURRENT_DIR . "view/" . $file . "\"><img alt=\"" . $file . "\" src=\"" . URL_CURRENT_DIR . ".thumbs/" . $file . "\" /></a></div>\n";
				print "</li>\n";
			}
			print "</ul>";
		} else {
			print "No Images Found";
		}
		print "</div>";
		$this->_galleryNav();
	}
		
	private function _view() {
		print "<center>";
		$this->_viewNav();
		print "<img alt=\"" . $file . "\" src=\"" . URL_CURRENT_DIR . $this->_vars["image"] . "\" />";
		$this->_viewNav();
		print "</center>";
	}
	
	private function _viewNav() {
		if($this->_vars["lastImage"] || $this->_vars["nextImage"]) {
			print "<ul class=\"viewNav\">";
		}
		if($this->_vars["lastImage"]) {
			print '<li><div><a href="' . URL_CURRENT_DIR . 'view/' . $this->_vars["lastImage"] . '"><img alt="' . $file . '" src="'. URL_CURRENT_DIR . '.thumbs/' . $this->_vars["lastImage"] . '" /></a></div></li>';
		} else {
			print '<li><div><a class="end" href="' . URL_CURRENT_DIR . $this->_vars["galleryPage"] . '">No More Images</a></div></li>';
		}
		print '<li><div><a class="end" href="' . URL_CURRENT_DIR . $this->_vars["galleryPage"] . '">Up To Gallery</a></div></li>';
		if($this->_vars["nextImage"]) {
			print '<li><div><a href="' . URL_CURRENT_DIR . 'view/' . $this->_vars["nextImage"] . '"><img alt="' . $file . '" src="'. URL_CURRENT_DIR . '.thumbs/' . $this->_vars["nextImage"] . '" /></a></div></li>';
		} else {
			print '<li><div><a class="end" href="' . URL_CURRENT_DIR . $this->_vars["galleryPage"] . '">No More Images</a></div></li>';
		}
		if($this->_vars["lastImage"] || $this->_vars["nextImage"]) {
			print "</ul>";
		}
	}
	
	private function _subDirs() {
		if($this->_vars["subDirs"] || URL_CURRENT_DIR != URL_BASE_DIR) {
			print "<h2>Galleries</h2>";
			print "<ul class=\"subDirs\">";
			if(URL_CURRENT_DIR != URL_BASE_DIR) {
				print '<li><div><a href="' . URL_CURRENT_DIR . '..">Parent</a></div></li>';
			}
			if($this->_vars["subDirs"]) {	
				foreach($this->_vars["subDirs"] as $dir) {
					print '<li><div><a href="' . URL_CURRENT_DIR . $dir . '/"><img src="' . URL_CURRENT_DIR . $dir . '/.thumbs/.dirpreview.jpg" alt="' . $dir . '" /></a></div></li>';
				}
			}
			print "</ul>";
		}
	}
	
	private function _header() {
		return ' <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
				"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
				<html>
				<head>
				<title>Pictet2' . $this->_vars["title"] . '</title>
				<style type="text/css">
				@import "' . URL_BASE_DIR . '.css/pictet.css";
				</style>
				</head>
				
				<body>
				<center><h1>Pictet<sup>2</sup>' . $this->_vars["title"] . '</h1></center>' . "\n";
	}
	
	private function _galleryNav() {
		if($this->_vars["previousPage"] || $this->_vars["nextPage"]) {
			print "<center><p>";
			print "<small>Page " . GALLERY_PAGE . " of " . $this->_vars["lastPage"] . "</small><br />";
		}
		if($this->_vars["lastPage"] && $this->_vars["previousPage"]) {
			print '&nbsp;&nbsp;<a href="' . URL_CURRENT_DIR . '">|&lt;&lt;</a>&nbsp;&nbsp;';
		} else {
			print '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
		}
		if($this->_vars["previousPage"]) {
			print '&nbsp;&nbsp;<a href="' . URL_CURRENT_DIR . $this->_vars["previousPage"] . '">&lt;&lt;</a>&nbsp;&nbsp;';
		} else {
			print '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
		}
		if($this->_vars["nextPage"]) {
			print '&nbsp;&nbsp;<a href="' . URL_CURRENT_DIR . $this->_vars["nextPage"] . '">&gt;&gt;</a>&nbsp;&nbsp;';
		} else {
			print '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
		}
		if($this->_vars["lastPage"] && $this->_vars["nextPage"]) {
			print '&nbsp;&nbsp;<a href="' . URL_CURRENT_DIR . $this->_vars["lastPage"] . '">&gt;&gt;|</a>&nbsp;&nbsp;';
		}  else {
			print '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
		}
		if($this->_vars["previousPage"] || $this->_vars["nextPage"]) {
			print "</p></center><br />";
		}
	}
	
	private function _footer() {
		return '
				</body>
				</html>';
	}
	
	private function _cleanTemplates($content) {
		return $content;
	}
	
	private function _css() {
		return '@CHARSET "UTF-8"; 
				html, body { height: 100%; width: 100%; margin: 0; padding: 0; font-family: arial, san-serif; }
				ul#gallery, ul#gallery li { margin: 0; padding: 0; list-style-type: none; }
				ul#gallery { display: table; width: 968px; padding-left: 40px; padding-top: 40px; border: 1px solid #b9b9b9; background-color: #f3f3f3; }
				ul#gallery li { border: 1px solid #C6C6C6; background-color: #e4e4e4; width: 190px; height: 190px; float: left; margin-right: 40px; margin-bottom: 40px; }
				ul#gallery li div { width: 190px; height: 190px; text-align: center; display: table-cell; vertical-align: middle; }
				ul#gallery li img { padding: 1px; border: 1px solid #C6C6C6; }
				ul.viewNav, ul.viewNav li { margin: 0; padding: 0; list-style-type: none; }
				ul.viewNav { display: table; width: 616px; padding-left: 10px; padding-top: 10px; border: 1px solid #b9b9b9; background-color: #f3f3f3; margin: 10px;}
				ul.viewNav li { border: 1px solid #C6C6C6; background-color: #e4e4e4; width: 190px; height: 190px; float: left; margin-right: 10px; margin-bottom: 10px; }
				ul.viewNav li div { width: 190px; height: 190px; text-align: center; display: table-cell; vertical-align: middle; }
				ul.viewNav li img { padding: 1px; border: 1px solid #C6C6C6; }
				#holder { position: relative; text-align: center; width: 968px; margin-left: auto; margin-right: auto; }
				a, a:visited, a:hover, a:active { font-size: 14px; font-weight: bold; text-decoration: none; color: black;}
				a:hover { color: #486DA1; }
				ul#viewNav li div a.end, ul#viewNav li div a:hover.end { text-align: center; display: table-cell; vertical-align: middle; height: 190px; width: 190px; }
				h2 { margin: 0px; padding: 0px; }
				ul.subDirs, ul.subDirs li { margin: 0; padding: 0; list-style-type: none; }
				ul.subDirs { display: table; margin: 10px auto 10px auto; padding-left: 10px; padding-top: 10px; border: 1px solid #b9b9b9; background-color: #f3f3f3;}
				ul.subDirs li { border: 1px solid #C6C6C6; background-color: #e4e4e4; width: 110px; height: 110px; float: left; margin-right: 10px; margin-bottom: 10px; }
				ul.subDirs li div { width: 110px; height: 110px; text-align: center; display: table-cell; vertical-align: middle; }
				ul.subDirs li img { padding: 1px; border: 1px solid #C6C6C6; }';
	}
	
}